<?php 
  ob_start();
  if(!isset($_SESSION)){
	session_start();
	$message="";
  } require_once('../../Connections/microassur.php'); require_once('../../utils/fonctions.php');?>
<?php

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
function ajoutDate2($date,$m,$j,$a)
	{
		$date=explode('-',$date); 
		return $datefin=date("d-m-Y", mktime(0, 0, 0, $date[1]+($m), $date[0] +($j), $date[2]+($a)));
	}

// fonction qui d�termine si ou ou non c'est une garantie souscrite

function verifgarantiesouscrite($formule) {
	$val="false";
	 $sql="SELECT * FROM tarif WHERE Identifiant_formule='$formule'";
	$res = mysql_query($sql);
	$row = mysql_fetch_object($res);
	if($row->Identifiant_garantie>0){
		$val="true";
	}
	return $val;
}
function getDateFinEcheanceContrat4($Identifiant_contrat) {
	$sql="select Date_echeance_contrat from contrat where Identifiant_contrat='$Identifiant_contrat' ";
	$res=mysql_query($sql);
	if(mysql_num_rows($res)){
		$row = mysql_fetch_object($res);
	}
	return $row->Date_echeance_contrat;
}
$col_rs_tarif = "-1";
if (isset($_SESSION['formule'])) {
  $col_rs_tarif = $_SESSION['formule'];
   //$_SESSION['garantie']; variable inutile (louis)
  $col_id_contrat = $_SESSION['idcontrat'];
}
$bool2=true;
$bool3=true;
if(isset($_POST['MM_insert']))$vide=!empty($_POST['datereglement']) && !empty($_POST['refreglement']) && !empty($_POST['montantecheanceregle'])   ;
if( !empty($_POST['montantassure']) )$bool2= verifNumeric($_POST['montantassure']);
if (!empty($_POST['montantdroitentre']) )$bool3= verifNumeric($_POST['montantdroitentre']);
if(isset($_POST['MM_insert']))$bool_1=datevalide($_POST['datereglement']) && datevalider($_POST['datereglement']) && verifLibelle('refreglement') && verifNumeric($_POST['montantecheanceregle']) && $bool2 && $bool3 ;
mysql_select_db($database_microassur, $microassur);

   $query_rs_tarif = sprintf("SELECT * FROM tarif WHERE Identifiant_formule = %s", GetSQLValueString($col_rs_tarif, "int"));
$rs_tarif = mysql_query($query_rs_tarif, $microassur) or die(mysql_error());
$row_rs_tarif = mysql_fetch_assoc($rs_tarif);
$totalRows_rs_tarif = mysql_num_rows($rs_tarif); 

if( $totalRows_rs_tarif>0 && isset($_POST['MM_insert']) && $_POST['MM_insert']=='form1' && $bool_1 && $vide)
{ 
//echo "*********************".$_SESSION['formule'];
	//$_SESSION['tarif']=$row_rs_tarif['Montant_tarif_base'];
	
	
	//$bool=
	//if(1)
		
		if($_POST['freqpaiement']=='A')$_SESSION['tarif']= 0;
		if($_POST['freqpaiement']=='M')$_SESSION['tarif']=$row_rs_tarif['Taux_echeance_mensuel'];
		if($_POST['freqpaiement']=='T')$_SESSION['tarif']=$row_rs_tarif['Taux_echeance_trimestriel'];
		if($_POST['freqpaiement']=='S')$_SESSION['tarif']=$row_rs_tarif['Taux_echeance_semestriel'];
		
// r�cupration des garanties souscrites par le contrat
//echo'<br>';
$typeGarantieCalcul = verifgarantiesouscrite($col_rs_tarif);
 if($typeGarantieCalcul=="true"){
 $sql1="select * from garantiesouscrite where Identifiant_contrat='$col_id_contrat' and Identifiant_formule='$col_rs_tarif'";
$res1 =  mysql_query($sql1);
//if(mysql_num_rows($res1)){
	while($row1 = mysql_fetch_object($res1)){
	$identifiant_garantie=$row->Identifiant_garantie;
	//echo yes;
	if($row_rs_tarif['Type_tarif']=='M')
		{	//2.1
			
//			echo Montant_tarif_base__.$row_rs_tarif['Montant_tarif_base'];echo"<br>";
//			echo taux_fra_ech__.$_SESSION['tarif'];echo"<br>";
			$montantcotisation1=$row_rs_tarif['Montant_tarif_base']+ ceil(($row_rs_tarif['Montant_tarif_base']* ($_SESSION['tarif']/100)));
			
			//$montantfraisecheance1=$montantcotisation - $row_rs_tarif['Montant_tarif_base'];
			$Montant_tarif_base+=$row_rs_tarif['Montant_tarif_base'];
		}
		elseif($row_rs_tarif['Type_tarif']=='T' && !empty($_POST['montantassure']))
		{
//			echo"<br>TAUX<br>";
//			echo Montant_tarif_base__.$row_rs_tarif['Montant_tarif_base'];echo"<br>";
//			echo taux_fra_ech__.$_SESSION['tarif'];echo"<br>";
//			echo Montant_int__.$montant_int=$row_rs_tarif['Taux_tarif_base'] * $_POST['montantassure'];	echo"<br>";	
			$montant_int=($row_rs_tarif['Taux_tarif_base']/100 ) * $_POST['montantassure']; 
					$montantcotisation1=ceil($montant_int + ($montant_int * ($_SESSION['tarif']/100)));
		
			$montant_int2=($row_rs_tarif['Taux_tarif_base']/100) * $_POST['montantassure']; 
			$mont_int3+=$montant_int2;
			
		}
		$montantcotisation +=$montantcotisation1;
	
	
}
	if($row_rs_tarif['Type_tarif']=='M'){
		$montantfraisecheance=$montantcotisation-$Montant_tarif_base;
	}
 	if($row_rs_tarif['Type_tarif']=='T'){
		$montantfraisecheance=$montantcotisation-$mont_int3;
	}
	
 }else{
	if($row_rs_tarif['Type_tarif']=='M')
		{	//2.1
//			echo Montant_tarif_base__.$row_rs_tarif['Montant_tarif_base'];echo"<br>";
//			echo tari__.$_SESSION['tarif'];echo"<br>";
			
			$montantcotisation=ceil($row_rs_tarif['Montant_tarif_base']+ ($row_rs_tarif['Montant_tarif_base']* ($_SESSION['tarif']/100)));
			//echo montantcotisation__.$montantcotisation;
			
			// calcul �ch�ance
			$montantfraisecheance=$montantcotisation - $row_rs_tarif['Montant_tarif_base'];	
			$Montant_tarif_base=$row_rs_tarif['Montant_tarif_base'];
		
		}
		elseif($row_rs_tarif['Type_tarif']=='T' && !empty($_POST['montantassure']))
		{
					//2.2
//			echo"<br>TAUX<br>";
//			echo taux_tarif_base__.$row_rs_tarif['Taux_tarif_base'];echo"<br>";
//			echo taux_fra_ech__.$_SESSION['tarif'];echo"<br>";
//			echo Montant_int__.$montant_int=($row_rs_tarif['Taux_tarif_base']/100 )* $_POST['montantassure'];	echo"<br>";
					
			$montant_int=($row_rs_tarif['Taux_tarif_base']/100 )* $_POST['montantassure']; 
					$montantcotisation=ceil($montant_int + ($montant_int * ($_SESSION['tarif']/100) ));
			
			// calcul �ch�ance
			$montant_int=($row_rs_tarif['Taux_tarif_base']/100) * $_POST['montantassure']; 
			$montantfraisecheance=$montantcotisation - $montant_int;
		}
 	
}
	
	
 //echo Montant_cotisation__.$_SESSION['montantcotisation']=$montantcotisation;echo"<br>";
		$_SESSION['montantcotisation']=$montantcotisation;
	$_SESSION['montantfraisecheance']=$montantfraisecheance;
	if( isset($_POST['MM_insert']) && $_POST['MM_insert']=='form1')
	{
		//4
		if($_POST['freqpaiement']=='A')$nbreglement=1;
		if($_POST['freqpaiement']=='M')$nbreglement=12;
		if($_POST['freqpaiement']=='T')$nbreglement=4;
		if($_POST['freqpaiement']=='S')$nbreglement=2;
		//echo nb__.$nbreglement;echo"<br>";
//		echo ECH__.$montantecheance=ceil($montantcotisation/$nbreglement);echo"<br>";
		$montantecheance=ceil($montantcotisation/$nbreglement);
		if(1)//$message.="<br>Inégalité montant  echeance";
		//else
		{
		//echo "*********************";	echo"<br>";	
			//5
			$m1=1 ;
			$m=1;
			$date=1 ;
			$message1="";
			$n=1;
			//Correction anomalie 691
//			$bool =verifDate($_SESSION['dateeffet'],$_POST['datereglement']); 
//			if(!$bool){	$date=0;}
			$bool2 = getDiffDate($_SESSION['dateeffet'],$_POST['datereglement']);
			if($bool2=="false"){$date=0;}	
				
				if(!empty($_POST['montantassure']) && $row_rs_tarif['Type_tarif']=='M'){$m=0;}
					
					if(empty($_POST['montantassure']) && $row_rs_tarif['Type_tarif']=='T'){$m1=0;}
					//echo m1__.$_POST['montantecheanceregle'];echo"<br>";
				//echo m2__.$montantecheance;
					if($_POST['montantecheanceregle']!=$montantecheance){$n=0; }

					if($m1==1 && $m==1 && $date==1 && $n==1)
					{ 
						//echo "2*********************";		
						//8
						$montantassure= $_POST['montantassure'];
						 mysql_query("START TRANSACTION"); $verif=true;
						 
						if($_POST['modepaiement'] != 'P'){
							$req=mysql_query("update contrat set Identifiant_RIB = NULL, Mode_paiement='".$_POST['modepaiement']."' , Frequence_paiement='".$_POST['freqpaiement']."', Montant_assure_contrat='".$montantassure."' where Numero_contrat='".$_SESSION['contrat']."'")or die(mysql_error());
						}else{
							$req=mysql_query("update contrat set Mode_paiement='".$_POST['modepaiement']."' , Frequence_paiement='".$_POST['freqpaiement']."', Montant_assure_contrat='".$montantassure."' where Numero_contrat='".$_SESSION['contrat']."'")or die(mysql_error());
						}
						if(!$req) { mysql_query("rollback");$verif=false; $message.=colorer("Problème modification contrat (informations paiement), contactez la DSI ","false");} 
						else mysql_query("commit");
							$_SESSION['modepaiement']=$_POST['modepaiement'];
						
						//9
						$datefincotis=ajoutDate($_SESSION['dateeffet'],12,-1,0);
						//$requete=mysql_query("select * from cotisation where Date_debut_cotisation='".."' and Date_fin_cotisation='".."' and Numero_avenant_cotisation='".."' and Montant_base_cotisation='".."' and ");
						// Vérifier si une insertion
						$date_finEcheance_contrat = getDateFinEcheanceContrat4($_SESSION['idcontrat']);
						 mysql_query("START TRANSACTION");
						//echo  $sql="insert into cotisation values('','".dateEN2FR($_SESSION['dateeffet'])."','$date_finEcheance_contrat','0','".$montantcotisation."','".$montantfraisecheance."','".$_POST['montantdroitentre']."','".$_SESSION['idcontrat']."')";
						
						if($row_rs_tarif['Type_tarif']=='M'){
						$req1=mysql_query("insert into cotisation values('','".dateEN2FR($_SESSION['dateeffet'])."','$date_finEcheance_contrat','0','$Montant_tarif_base','".$montantfraisecheance."','".$_POST['montantdroitentre']."','".$_SESSION['idcontrat']."')") or die(mysql_error());
						}else{
							$req1=mysql_query("insert into cotisation values('','".dateEN2FR($_SESSION['dateeffet'])."','$date_finEcheance_contrat','0','".$montant_int."','".$montantfraisecheance."','".$_POST['montantdroitentre']."','".$_SESSION['idcontrat']."')") or die(mysql_error());
						
						}
						
						
						if(!$req1) {  mysql_query("rollback");$verif=false; $message.=colorer("Problème création cotisation, contactez la DSI","false");}
						else  mysql_query("commit");
						$datefin=$date_finEcheance_contrat;
						$idcontrat=$_SESSION['idcontrat'];
						
						//Création des variables de session pour alimenter le formlaire
							$_SESSION['modepaiement']=$_POST['modepaiement'];
							$_SESSION['fredpaiement']=$_POST['freqpaiement'];
							$_SESSION['montantcotis']=$_POST['montantcotis'];
							
							$_SESSION['refreglement']=$_POST['refreglement'];
							$_SESSION['fraisecheance']=$_POST['fraisecheance'];
							$_SESSION['datereglement']=$_POST['datereglement'];
							$_SESSION['refreglement']=$_POST['refreglement'];
							$_SESSION['montantecheanceregle']=$_POST['montantecheanceregle'];
							$_SESSION['montantdroitentre']=$_POST['montantdroitentre'];
							$_SESSION['montantassure']=$_POST['montantassure'];
							$_SESSION['montantcotisation']=$montantcotisation;
							$_SESSION['montantecheance']=$montantecheance;
							$_SESSION['montantfraisecheance']=$montantfraisecheance;
											
						
						$max=-1;
						$requete=mysql_query("select max(Identifiant_cotisation) as id from cotisation ")or die(mysql_error());
						if($requete)
						{
							 $reponse=mysql_fetch_array($requete);
							 $max=$reponse["id"]; 
						 }
						else $verif=false;
						//10
						
						//calcul du premier échéance 	
						$i=0;
						if($nbreglement==12) $nbmois =1;
						
						if($nbreglement==2)$nbmois =6;
;
						if($nbreglement==4)$nbmois =3;

						if($nbreglement==1)$nbmois =12;
						
						
						
					 	$datefin=ajoutDate($_SESSION['dateeffet'],$nbmois,-1,0);
						
						 
						$req=mysql_query("select * from echeancier where Date_debut_echeance='".dateEN2FR($_SESSION['dateeffet'])."' and Date_fin_echeance='".dateEN2FR($datefin)."' and Etat_echeance='R' and Montant_echeance='$montantecheance' and Identifiant_cotisation='".$max."'"); 
						
						$num=0;
						if($req)
						{
							
							$num=mysql_num_rows($req);
						}
						else $verif=false;
						//echo $datefin;
						 if($num==0)
						 {
						 	$req=mysql_query("insert into echeancier values('','".dateEN2FR($_SESSION['dateeffet'])."','".dateEN2FR($datefin)."','R','$montantecheance','".$max."')"); 
						 if(!$req)$message.=colorer("Problème création échéance, contactez la DSI ","false");
						 
						 }
						$date_fin = str_replace('/','-',$datefin);
						$datedebut=ajoutDate2($date_fin,0,1,0);
						$i++;
						while($i<$nbreglement)
						{	 
						$datefin=ajoutDate2($datedebut,$nbmois,-1,0);
							$req=mysql_query("select * from echeancier where Date_debut_echeance='".dateEN2FR($datedebut)."' and Date_fin_echeance='".dateEN2FR($datefin)."' and Etat_echeance='AA' and Montant_echeance='$montantecheance' and Identifiant_cotisation='".$max."'"); 
							
							$num=0;
							if($req)
								{
									
								$num=mysql_num_rows($req); 
								}
								else $verif=false;
							
							 if($num==0)
								 {
									$req=mysql_query("insert into echeancier values('','".dateEN2FR($datedebut)."','".dateEN2FR($datefin)."','AA','$montantecheance','".$max."')");
								if(!$req) {$verif=false;$message.=colorer("Problème création échéance, contactez la DSI ","false");}
								 
								 }
								$datedebut=ajoutDate2($datefin,0,1,0);
							
							$i++;				
					}
					// modification de la date de fin d'�cheance de la garantie souscrite
					$idcontrat = $_SESSION['idcontrat'];
					
					
						if($verif==true) mysql_query("commit");
						else mysql_query("rollback");
						$ok=1;
						if($_POST['modepaiement']!='P')header("location:index.php?rib=1");
						
					} 
/*********************** A  modifier avec les messages d'erreur de la cliente et décommenter **************************/
					//modification anomalie 691 : j'ai mis en commentaire � voir avec amct
					elseif($date==0)$message1.=colorer(" La date de règlement ne peut être postérieure à la date d’effet","false");
					elseif($n==0)$message1.=colorer("Le montant de l’échéance réglée est faux","false");
					elseif($m==0)$message1.=colorer("Vous ne pouvez saisir un montant assuré pour ce type de produit","false");
					elseif($m1==0)$message1.=colorer("Vous devez saisir un montant assuré pour ce type de produit ","false");
					
				
			}
			
		
			
		
	}
}
elseif(isset($_POST['MM_insert']) && !$vide)
{
if(empty($_POST['datereglement']))$message=colorer("Vous devez saisir la date du règlement ","false");
elseif(empty($_POST['refreglement']))$message=colorer("Vous devez saisir la référence du règlement  ","false");
elseif(empty($_POST['montantecheanceregle']))$message=colorer("Vous devez saisir le montant de l’échéance réglée","false");

}

elseif(isset($_POST['MM_insert']) && !$bool_1)
{ 
if(!datevalider($_POST["datereglement"]))$message=colorer("Le format de la date du règlement est JJ-MM-SSAA, JJ étant le jour, MM le mois, SS le siècle, AA l’année","false");
elseif(!datevalide($_POST["datereglement"]))$message=colorer("La date du règlement est incorrecte","false");

elseif( !verifLibelle("refreglement"))$message=colorer("La référence du règlement saisie comporte des caractères spéciaux interdits ","false");
elseif(!verifNumeric($_POST["montantecheanceregle"]))$message=colorer("Le montant de l’échéance réglée doit être numérique ","false");
elseif(!empty($_POST['montantdroitentre']) && !verifNumeric($_POST["montantdroitentre"]))$message=colorer("Le montant  des droits d’entrée  doit être numérique ","false");
elseif(!empty($_POST['montantassure']) && !verifNumeric($_POST["montantassure"]))$message=colorer("Le montant assuré réglée doit être numérique ","false");


}
if(isset($_GET["isRib"])==1){
	echo yes;
	$message.= colorer("Vous devez rattacher un RIB au contrat","false");
}else{
	
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paiement</title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]--></head>

<body>
<div id="sf_menu1">
<h3>Production </h3>
<?php
	
	if(isset($message) && !empty($message)){
		echo $message;
	}
	if(isset($message1) && !empty($message1)){
		echo $message1;
	}
	$nommodule="Souscription contrat";
	
	$nom_module_saisie="Paiement";
?>
</div>
<div class="cleared"></div>

<div class="corps1">
<div class="cleared"></div>
</head>

<body>
<form id="form1" name="form1" method="post" action="index.php">
 <div class="imgleft2"></div>
	<div class="imgmiddle2">
    <div class="btn">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nommodule; ?></h5>
        </span><span class="btnright"></span>
    </div>
  	<div class="btn1">
    	<span class="btnleft"></span>
        <span class="btnmiddle">
        	<h5><?php echo $nom_module_saisie; ?></h5>
        </span>
        <span class="btnright"></span>
    </div>
	<div class="formulaire">
  <table width="706" height="269" class="tabform">
    <tr>
      <td >FREQUENCE DE PAIEMENT</td>
      <td colspan="2">
      <select name="freqpaiement" id="freqpaiement"  >
      <?php $requete=mysql_query("select elementdico.* from dictionnaire,elementdico where dictionnaire.Code_table='M0007' and dictionnaire.Identifiant_table=elementdico.Identifiant_table");
	 
	  while($reponse=mysql_fetch_array($requete)) {?>
        <option <?php  if(isset($_SESSION['freqpaiement'])) echo remind_select1('freqpaiement',$reponse["Code_element"]); else echo remind_select('freqpaiement',$reponse["Code_element"]);?> value="<?php echo $reponse["Code_element"];?>"><?php echo $reponse["Nom_element"];?></option>
        <?php }?>
        </select></td>
    </tr>
    <tr>
      <td>MODE DE PAIEMENT</td>
      <td colspan="2"><select name="modepaiement" id="modepaiement"  >
      <?php $requete=mysql_query("select elementdico.* from dictionnaire,elementdico where dictionnaire.Code_table='M0006' and dictionnaire.Identifiant_table=elementdico.Identifiant_table");
	 // corection anomalie 692 htmlentities($reponse["Nom_element"], ENT_QUOTES, "UTF-8");
	  while($reponse=mysql_fetch_array($requete)) {?>
        <option <?php if(isset($_POST['modepaiement'])) echo remind_select('modepaiement',$reponse["Code_element"]); else  echo remind_select('modepaiement',$reponse["Code_element"]);?> value="<?php echo $reponse["Code_element"];?>"><?php echo htmlentities($reponse["Nom_element"], ENT_QUOTES, "UTF-8");?></option>
        <?php }?>
        </select>
      </td>
    </tr>
    <tr>
      <td>MONTANT DE COTISATION</td>
      <td colspan="2"><label>
        <input   name="montantcotis" type="text" class="resizeall" id="montantcotis" value="<?php if(isset($_SESSION["montantcotisation"])) echo $_SESSION["montantcotisation"]?>" maxlength="10" readonly="readonly" /> <!--disabled="disabled"-->
      </label></td>
    </tr>
    <tr>
      <td>DONT FRAIS ECHEANCE</td>
      <td colspan="2"> <input name="fraisecheance" type="text" class="resizeall" id="fraisecheance"  value="<?php if(isset($_SESSION["montantfraisecheance"])) echo $_SESSION["montantfraisecheance"]?>" maxlength="10"  readonly="readonly" /></td> <!--disabled="disabled"-->
    </tr>
    <tr>
      <td>DATE ET REFERENCE DU REGLEMENT</td>
      <td width="144"><label>
        <input name="datereglement" type="text"  class="resizeall"  id="datereglement" value="<?php if(isset($_POST['datereglement'])) echo $_POST['datereglement'];elseif(isset($_SESSION["datereglement"])) echo $_SESSION["datereglement"]?>" maxlength="10" />
      </label></td>
      <td width="154"><label>
        <input  name="refreglement" size="27" type="text" class="resizeall" id="refreglement"  value="<?php if(isset($_POST['refreglement'])) echo $_POST['refreglement'];elseif(isset($_SESSION["refreglement"])) echo $_SESSION["refreglement"]?>" maxlength="30"/>
      </label></td>
    </tr>
    <tr>
      <td>MONTANT ECHEANCE REGLEE</td>
      <td colspan="2"><label>
        <input name="montantecheanceregle" type="text"   id="montantecheanceregle" value="<?php if(isset($_POST['montantecheanceregle'])) echo $_POST['montantecheanceregle'];elseif(isset($_SESSION["montantecheanceregle"])) echo $_SESSION["montantecheanceregle"]?>" maxlength="10"/>
      </label></td>
    </tr>
    <tr>
      <td>MONTANT DROITS D'ENTREE</td>
      <td colspan="2"><label>
        <input name="montantdroitentre" type="text" id="montantdroitentre" value="<?php if(isset($_POST['montantdroitentre'])) echo $_POST['montantdroitentre'];elseif(isset($_SESSION["montantdroitentre"])) echo $_SESSION["montantdroitentre"]?>" maxlength="10" />
      </label></td>
    </tr>
    <tr>
      <td>MONTANT ASSURE</td>
      <td colspan="2"><label>
        <input name="montantassure" type="text" id="montantassure" value="<?php if(isset($_POST['montantassure'])) echo $_POST['montantassure'];elseif(isset($_SESSION["montantassure"])) echo $_SESSION["montantassure"]?>" maxlength="10"/>
      </label></td>
    </tr>
  </table>
  
  </div></div>
    

<div class="imgright2"></div>	
<?php 

if((isset($_SESSION['modepaiement'])) && (!$_SESSION['modepaiement']) or (!empty($message))){
		
	?>		
<div class="bt1"> <a href="#"><span class="btleft"></span>
        <span class="btmiddle">Référence externe</span>
        <span class="btright"></span>
    </a></div> 
   <?php 
  }
  elseif((isset($_SESSION['modepaiement'])) && ($_SESSION['modepaiement']) && (empty($message))){
   ?>
   <div class="bt1"> <a href="refexterne/saisierefexterne.php<?php if(!empty($_SERVER['QUERY_STRING'])) echo "?".$_SERVER['QUERY_STRING']?>"><span class="btleft"></span>
        <span class="btmiddle">Référence externe</span>
        <span class="btright"></span>
    </a></div> 
    <?php }?>
   <?php 
//if((!isset($_POST['modepaiement'])) ){
//	  echo " <div class=\"bt\"> <a href=\"#\"><span class=\"btleft\"></span>
//        <span class=\"btmiddle\">RIB</span>
//        <span class=\"btright\"></span>
//    </a></div> "; }
	  if(( ( isset($_POST['modepaiement']) && $_POST['modepaiement']=="P")  || ( isset($_SESSION['modepaiement']) && $_SESSION['modepaiement']=="P"))){ 
	  //	echo yes;
	  	echo "	  	  
	  <div class=\"bt\"> <a href=\"rib/index.php\"><span class=\"btleft\"></span>
        <span class=\"btmiddle\">RIB</span>
        <span class=\"btright\"></span>
    </a></div>";
	  }else{
	  	echo " <div class=\"bt\"> <a href=\"#\"><span class=\"btleft\"></span>
        <span class=\"btmiddle\">RIB</span>
        <span class=\"btright\"></span>
    	</a></div> ";
	  }
	  
	  ?>	<div class="bt"> <a href="../contrat/index.php<?php if(isset($_SESSION['modepaiement']) && $_SESSION['modepaiement']=="P")echo "?rib=1" ?>"><span class="btleft"></span>
        <span class="btmiddle">Retour</span>
        <span class="btright"></span>
    </a></div>  
   <div class="bt"> <a href="../contrat/index.php"><span class="btleft"></span>
        <span class="btmiddle">Annuler</span>
        <span class="btright"></span>
    </a></div>  
    <?php  if(isset($ok) && $ok==1 || (isset($_GET['rib']) && $_GET['rib'])){?>   
	
      <div class="bt">
	<span class="btleft"></span><a href="#"></span>
	 <span class="btmiddle">Valider</span>
     <span class="btright"></span></a></div>   
     <?php 
	 } else
	 { ?><div class="bt">
	<span class="btleft"></span><input type="submit"  value="Valider"  class="resizeall btmiddle"/>
    <span class="btright"></span></div>
    <?php }
	?>       
      
	      
   <div class="cleared"></div>
  <input type="hidden" name="MM_insert" value="form1" />
</form> </div>



</body>
</html>
<?php
mysql_free_result($rs_tarif);
?>
<?php ob_end_flush();?>